<template>
  <div class="goodslist-container">
    <div
      class="goodslist-item"
      v-for="item in goodslist"
      :key="item.id"
      @click="getDetail(item.id)"
    >
      <img :src="item.img_url" alt />
      <h1 class="goodslist-title">{{item.title}}</h1>
      <div class="goodslist-info">
        <p class="goodslist-price">
          <span class="goodslist-now">￥{{item.sell_price}}</span>
          <span class="goodslist-old">￥{{item.market_price}}</span>
        </p>
        <p class="goodslist-sell">
          <span>热卖中</span>
          <span>剩{{item.stock_quantity}}件</span>
        </p>
      </div>
    </div>
    <mt-button type="danger" size="large" @click="getMore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageindex: 1,
      goodslist: []
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.axios
        .get("api/getgoods?pageindex=" + this.pageindex)
        .then(response => {
          if (response.data.status === 0) {
            this.goodslist = this.goodslist.concat(response.data.message);
          }
        });
    },
    getMore() {
      this.pageindex++;
      this.getGoodsList();
    },
    getDetail(id) {
      this.$router.push("/home/goodsinfo/" + id);
    }
  }
};
</script>
<style lang="scss">
.goodslist-container {
  padding: 3.5px 7px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  .goodslist-item {
    margin: 4px 0;
    padding: 2px;
    width: 49%;
    border: 1px solid #ccc;
    box-shadow: 0 0 9px #ccc;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    img {
      width: 100%;
    }
    .goodslist-title {
      font-size: 14px;
    }
    .goodslist-info {
      background-color: #eee;
      p {
        margin: 0;
        padding: 5px;
      }
      .goodslist-price {
        .goodslist-now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        .goodslist-old {
          font-size: 12px;
          text-decoration: line-through;
          margin-left: 10px;
        }
      }
      .goodslist-sell {
        display: flex;
        justify-content: space-between;
        font-size: 14px;
      }
    }
  }
}
</style>